#ifndef __PTHREADKEYS_H__
#define __PTHREADKEYS_H__

#include "util/Pool.h"

// Singleton class, shared by instance of PthreadInterface, PthreadInterfaceLock, ...
// ..., PthraedInterfaceTM.
class PthreadKeys {
  public:
    NEW_DELETE_OPERATORS_H(PthreadKeys,NoSuper);
    PthreadKeys();
    ~PthreadKeys();
    static PthreadKeys *getInstance();
    static void removeInstance();
    int create (pthread_key_t* key, void (*destructor)(void*));
    int setspecific (pthread_key_t key, const void* value);
    void* getspecific (pthread_key_t key);
  protected:
    const int num_cpus;

    static const int MAX_KEYS = 4096;
    /** 
        Allocated statically to allow padding to segregate data used
        in simulation from data used in the simulator.
    */
    static void* key_data[MAX_NUM_CPUS][MAX_KEYS];

    int key_count;
  private:
    static PthreadKeys *instance;
};

#endif
